﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class EditParamsControl : MPBasicTemplate
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        TextBox dianname, diankey, dianvalue, txtID;
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            InitControl();
            string strid = base.Page.Request["ID"];
            if (!base.Page.IsPostBack) {
                
                if (string.IsNullOrEmpty(strid)) { txtID.Text = System.Guid.NewGuid().ToString().Replace("-", "").ToUpper(); } 
                else {
                    string action = base.Page.Request["action"];
                    if (action == "del")
                    {
                        string sql = "delete  from zs_params where id='" + strid + "'";
                        _EluZSDataProvider.RunSqlNon(sql);
                        base.Page.Response.Redirect("Params.aspx");
                    }
                    else
                    {
                        txtID.Text = strid;
                        EluZSProvider.Params _params = _EluZSDataProvider.GetParamO(strid);
                        dianname.Text = _params.Name;
                        diankey.Text = _params.Keyname;
                        dianvalue.Text = _params.Keyvalue;
                    }
                    
                }
            }
            Button savebtn = (Button)FindControl("savebtn");
            savebtn.Click += new EventHandler(savebtn_Click);
        }
        protected void InitControl() {
            dianname = (TextBox)FindControl("dianname");
            diankey = (TextBox)FindControl("diankey");
            dianvalue = (TextBox)FindControl("dianvalue");
            txtID = (TextBox)FindControl("txtID");
        }
        protected void savebtn_Click(object sender, EventArgs e)
        {
            string strid = base.Page.Request["ID"];
            EluZSProvider.Params _params = new EluZSProvider.Params();
            _params.Id = txtID.Text;
            _params.Name = dianname.Text;
            _params.Keyname = diankey.Text;
            _params.Keyvalue = dianvalue.Text;
            _params.Addtime = (DateTime?)System.DateTime.Now;
            bool save = _EluZSDataProvider.SaveParams(strid, _params);
            if (save) { base.Page.Response.Redirect("params.aspx"); }
        }
        
    }
}


